Hi everyone! Welcome to this penultimate class of the Fall semester. Next week is the second set of project presentations and then it is winter holidays. The goal of today is to 1) have some fun, 2) further build some of your practical skills wrangling and visualising data and 3) gain experience using an API.
See the slides on the course overview page for more information.
# Credit to danielle smith for this basis of this great little function:
# https://gist.github.com/smithdanielle/9913897
install_check <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
}
# Here is a list of the packages we will need today
packages = c("tidyverse", "polite",
"TMDb", "keyring", "glue", "lubridate", "ggpubr")
install_check(packages)
# Load tidyverse now, we'll load the others as we need them
library(tidyverse) # Liza's fave package of packages ever
library(glue) # awesome package that we don't have time to talk about
library(lubridate) # helps make dates much easier
library(polite) # let's us check the robotstxt, and also pass user agent information to the site, if we choose
bow("https://www.imdb.com/search/keyword/?keywords=christmas&ref_=kw_nxt&sort=moviemeter,asc&mode=detail&page=2&title_type=movie")
## <polite session> https://www.imdb.com/search/keyword/?keywords=christmas&ref_=kw_nxt&sort=moviemeter,asc&mode=detail&page=2&title_type=movie
## User-agent: polite R package - https://github.com/dmi3kno/polite
## robots.txt: 26 rules are defined for 1 bots
## Crawl delay: 5 sec
## The path is scrapable for this user-agent
Let’s looks at the robots.txt and Terms and Conditions ourselves.
browseURL("https://www.imdb.com/conditions")
browseURL("https://www.imdb.com/robots.txt")
So, can we ethically scrape IMDB?
Let’s take a look a different online movie database…
browseURL("https://www.themoviedb.org/terms-of-use")
back to the slides!
We can’t scrape ethically, but we can use the API. In fact, there exists a package to helps us do this easily in R!
You need the TMDb package that helps us access the API through R. We’re also going to install keyring which is a nice way to keep your private API key safe but still share all the code we’re using. `
library(TMDb) # provides access to the API
library(keyring) # for storing our API key
#This will create a pop-up prompting you for a password. Put your api key in there.
key_set("TMDB_API")
You can find more information in the documentation on CRAN or on this more interactive site
Let’s find out what kind of genre classifications we have.
genres <- genres_movie_list(key_get("TMDB_API"))$genres
genres
We can use these ids later to help us search things.
There is an error in the package for this function taht is suppowed to search keywrods, so I’ve edited it here.
search_keyword <- function(api_key, query, page=1){
if(page<1 || page>1000){
stop("page must be a number between 1 and 1000")
}
l <- list(page=page)
l <- l[!is.na(l)]
params <- paste("&", names(l), "=",l, sep="", collapse="")
url <- fromJSON(GET(URLencode(url<-paste("http://api.themoviedb.org/3/search/keyword?api_key=",
api_key, "&query=", query, params, sep="")))$url)
return(url)
}
Opportunity: Put in a pull request on the GitHub for the package to fix this function! https://github.com/AndreaCapozio/TMDb
# now I want to find all the Christmas keywords I could be searching
search_keyword(key_get("TMDB_API"), query = "christmas")
## $page
## [1] 1
##
## $results
## name id
## 1 christmas party 1441
## 2 saving christmas 12200
## 3 christmas lights 172742
## 4 christmas horror 186466
## 5 christmas music 186933
## 6 christmas card 188345
## 7 christmas spirit 193048
## 8 christmas reunion 196018
## 9 christmas 207317
## 10 christmas parade 228081
## 11 anti christmas 232431
## 12 christmas magic 240515
## 13 christmas dinner 252441
## 14 christmas food 254789
## 15 white christmas 258426
## 16 christmas eve 260365
## 17 christmas movie 265857
## 18 christmas pageant 269672
## 19 christmas pudding 270896
## 20 father christmas 272288
##
## $total_pages
## [1] 2
##
## $total_results
## [1] 39
Notice that this only has 20 rows… are there more Christmas keywords than just that? 20 seems like a suspicisoulsy tidy number…
Our problem is that this function can just pull one ‘page’ at a time, a page has 20 entries. Reading the documentation shows us that there are a maximum of 1000 pages but I think it is acutally 500 based on some testing.
Thankfully, we can find out how many pages there are by just looking at the total_pages list element. Convenient!
Now, we could do a for loop to get all the pages….but it seems like the more people program the less they like for loops. We can use the map functions from purrr to do what we want and keep our code very tidy. More info here: https://speakerdeck.com/jennybc/purrr-workshop.
# write a function that runs this for command for any given page
one_page <- function(x) search_keyword(key_get("TMDB_API"), query = "christmas", page = x)
# make a vector of the pages, from 1 to the max page for this search
pages <- 1:one_page(1)$total_pages
# now use map_dfr (map specifcally for returning data frames) instead of a for loop
christmas_keywords <- map_dfr(pages, function(x) one_page(x)$results)
christmas_keywords
# later, for searching multiple IDs I need to make them a string seperated by | for "OR" or , for "AND"
xmas_ids <- glue_collapse(christmas_keywords$id, sep="|")
xmas_ids
## 1441|12200|172742|186466|186933|188345|193048|196018|207317|228081|232431|240515|252441|254789|258426|260365|265857|269672|270896|272288|5570|170496|196450|209848|228415|230851|236216|240732|250130|255088|258805|258841|260508|262034|267190|272698|272807|272808|273274
# write a function that runs this for command for any given page
one_page <- function(x) search_keyword(key_get("TMDB_API"), query = "<PUT SEARCH TERM HERE", page = x)
# make a vector of the pages, from 1 to the max page for this search
pages <- 1:one_page(1)$total_pages
# now use map_dfr (map specifcally for returning data frames) instead of a for loop
my_keywords <- map_dfr(pages, function(x) one_page(x)$results)
my_keywords
# later, for searching multiple IDs I need to make them a string seperated by | for "OR" or , for "AND"
keywords_ids <- glue_collapse(christmas_keywords$id, sep="|")
keywords_ids
# change eval=FALSE in the chunk options, so that is TRUE
discover_movie() lets us do some searching based on a range of critera. I want movies that are Romance genre, and have “christmas” related keywords.
# Reusing the code structure above. This could probably be streamlined even better with a more general function
one_page <- function(x) discover_movie(key_get("TMDB_API"), with_genres = 10749, with_keywords = xmas_ids, page = x)
pages <- 1:one_page(1)$total_pages
christmas_romance <- map_dfr(pages, function(x) one_page(x)$results) %>%
mutate(genre_ids = as.character(genre_ids))
# write_csv(christmas_romance, "christmas_romance.csv")
Great resources for colours in R: http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf
christmas_romance <- read_csv("christmas_romance.csv") %>%
mutate(release_date = as_date(release_date))
##
## ── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## cols(
## id = col_double(),
## adult = col_logical(),
## backdrop_path = col_character(),
## genre_ids = col_character(),
## vote_count = col_double(),
## original_language = col_character(),
## original_title = col_character(),
## poster_path = col_character(),
## title = col_character(),
## video = col_logical(),
## vote_average = col_double(),
## popularity = col_double(),
## overview = col_character(),
## release_date = col_date(format = "")
## )
christmas_romance %>%
ggplot(aes(x = release_date)) +
geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
edit <- christmas_romance %>%
mutate(month = month(release_date, label = TRUE),
year = year(release_date),
ym = paste(year, month),
quarter = quarter(release_date, with_year = TRUE)) %>%
mutate(month = fct_expand(month, month.abb))
myplot <- edit %>%
filter(release_date > "2010-01-01") %>%
ggplot(aes(x = month)) +
geom_bar() +
scale_x_discrete(drop=FALSE) + # this bit of magic makes sure we don't drop the missing months
labs(title = "Release month of Christmas movies since 2010",
x = "Month",
y = "Number of movies released",
caption = "Source: https://www.themoviedb.org/") +
theme_minimal()
myplot
sweater_bkgd <- jpeg::readJPEG("sweater_bkgd.jpg")
edit %>%
filter(release_date > "2010-01-01") %>%
ggplot(aes(x = month)) +
ggpubr::background_image(sweater_bkgd) +
geom_bar(fill = "darkgreen") +
scale_x_discrete(drop=FALSE) + # this bit of magic makes sure we don't drop the missing months
labs(title = "Release month of Christmas movies since 2010",
x = "Month",
y = "Number of movies released",
caption = "By: @Liza_Bolton; Source: https://www.themoviedb.org/") +
theme(plot.background = element_rect(fill = "darkgreen"), text = element_text(color = "white"), axis.text= element_text(color = "white"))
ggsave("my_first_ugly_plot.png", width = 7, height = 4.5)
Background images in repo from:https://kosamari.github.io/sweaterify/ and https://depositphotos.com/110626704/stock-illustration-christmas-sweater-pattern.html
Use this API (or the data I have provided) and make an extremely ugly and hard to read graph! The sky is the limit (warning: stop if you make your own eyes bleed.)
Email us your ugly creations and if we get enough we can make a class gallery.
top10 <- edit %>%
arrange(desc(vote_count)) %>%
head(n = 10) %>%
select(title, poster_path)
top10
url <- paste0("https://image.tmdb.org/t/p/w1280/", top10$poster_path)
knitr::include_graphics(url)
# Here is an example of pulling a list (I got the id from the URL)
list_get(key_get("TMDB_API"), 7411)
## $created_by
## [1] "Taphive"
##
## $description
## [1] ""
##
## $favorite_count
## [1] 0
##
## $id
## [1] "7411"
##
## $items
## title video vote_average id vote_count
## 1 Rare Exports: A Christmas Tale FALSE 6.3 48395 305
## 2 Tokyo Godfathers FALSE 7.9 13398 507
## 3 A Christmas Story FALSE 7.3 850 763
## 4 Arthur Christmas FALSE 6.7 51052 891
## 5 Die Hard FALSE 7.7 562 7674
## 6 The Nightmare Before Christmas FALSE 7.8 9479 6284
## 7 Elf FALSE 6.6 10719 2574
## 8 Lethal Weapon FALSE 7.2 941 2977
## 9 Trading Places FALSE 7.2 1621 2030
## 10 Gremlins FALSE 7.1 927 4375
## 11 A Christmas Tale FALSE 6.9 8892 90
## 12 Home Alone FALSE 7.3 771 7200
## 13 Bad Santa FALSE 6.5 10147 1411
## 14 Kiss Kiss Bang Bang FALSE 7.2 5236 1776
## 15 The Polar Express FALSE 6.7 5255 4195
## 16 Home Alone 2: Lost in New York FALSE 6.6 772 6456
## 17 A Christmas Carol FALSE 6.8 17979 3201
## 18 It's a Wonderful Life FALSE 8.2 1585 2606
## 19 Scrooged FALSE 6.9 9647 900
## 20 The Santa Clause FALSE 6.4 11395 1281
## 21 A Christmas Carol FALSE 7.0 16716 109
## 22 Saint FALSE 5.1 45756 91
## 23 Black Christmas FALSE 6.9 16938 376
## 24 Love Actually FALSE 7.1 508 4481
## 25 National Lampoon's Christmas Vacation FALSE 7.2 5825 1408
## 26 Krampus FALSE 6.0 287903 1326
## release_date poster_path popularity adult
## 1 2010-12-03 /jzaweEESl54ejxo3EE5uNL8lgTn.jpg 8.646 FALSE
## 2 2003-12-29 /ukhvxpVcBsb1MpRRwiqEIwyKdUX.jpg 11.572 FALSE
## 3 1983-11-18 /naZ22fATqn5MiYbrskkZbVeiNoM.jpg 14.612 FALSE
## 4 2011-11-10 /brELZkSbkLrcCXJ0xt5hQUMXhut.jpg 22.432 FALSE
## 5 1988-07-15 /p5hURTvac8sxLRhe5hLchvfy5Pu.jpg 35.649 FALSE
## 6 1993-10-09 /e4pZZR1SZByveyWczQBmiXJ0lXP.jpg 44.010 FALSE
## 7 2003-10-09 /zDHFQmaxlTIJGQDfTrLTL9RK2tQ.jpg 26.142 FALSE
## 8 1987-03-06 /fTq4ThIP3pQTYR9eDepsbDHqdcs.jpg 22.683 FALSE
## 9 1983-06-07 /8mBuLCOcpWnmYtZc4aqtvDXslv6.jpg 12.483 FALSE
## 10 1984-06-07 /72Y1X9pMSjXQ7mKB6pBEoMhL0OQ.jpg 21.924 FALSE
## 11 2008-05-16 /yGLrE150vchL1q1e1UNmPRPKwii.jpg 7.135 FALSE
## 12 1990-11-16 /9wSbe4CwObACCQvaUVhWQyLR5Vz.jpg 3.583 FALSE
## 13 2003-11-26 /dt30keB9txHjYXuMzrqv6uJ499B.jpg 19.277 FALSE
## 14 2005-09-05 /5cPk7YIEP6Uj9tV0mKZSsI9MGbF.jpg 10.789 FALSE
## 15 2004-11-10 /hc2NFfInDrOiIgIy8TTjEZTvSkz.jpg 46.519 FALSE
## 16 1992-11-19 /uuitWHpJwxD1wruFl2nZHIb4UGN.jpg 63.949 FALSE
## 17 2009-11-04 /goHDZUnqZJ7FN4h48Qh6MzJNExl.jpg 45.332 FALSE
## 18 1946-12-20 /bSqt9rhDZx1Q7UZ86dBPKdNomp2.jpg 21.080 FALSE
## 19 1988-11-22 /uO0znfB2ZzTXA1IS7jkrjNbpkYK.jpg 9.537 FALSE
## 20 1994-11-11 /tBHDVtEcMl06FbCURRLGVg3TpXp.jpg 49.990 FALSE
## 21 1999-12-05 /oi1NcVDXlFEsdpLp37BJmFbVlg9.jpg 11.814 FALSE
## 22 2010-10-31 /pEPd4mgMwvz6aRhuWkmPUv98P1O.jpg 5.593 FALSE
## 23 1974-10-11 /qqO98sdPgptFgCua3Z4uZDuPcmP.jpg 6.921 FALSE
## 24 2003-09-07 /7QPeVsr9rcFU9Gl90yg0gTOTpVv.jpg 20.264 FALSE
## 25 1989-11-30 /64NKasFKx6aOTKRg4mv76l0IwZR.jpg 27.974 FALSE
## 26 2015-11-26 /9OiZVRWjdVLQMMhM7w6ocZjPJ6V.jpg 23.499 FALSE
## backdrop_path media_type genre_ids
## 1 /oJ6LNvBLNWW4W7f9ffGN7S6odde.jpg movie 14
## 2 /lHdG4SQa1GT2h52svEOyDEQ6bMD.jpg movie 16, 18
## 3 /bAXoW8wk7cBgPqK9pzPddvlAl2b.jpg movie 35, 10751
## 4 /t4WQ36MAZf1sgiPKocTa0KBGBKI.jpg movie 18, 16, 10751, 35
## 5 /qyNEqB6gl9V2GkiT88Pu36mqHnR.jpg movie 28, 53
## 6 /16lk65YfrDFIr6evkWRjSeOOSws.jpg movie 14, 16, 10751
## 7 /lmjjlXwNeRqmKBuA0a6jqOyTnZG.jpg movie 35, 10751, 14
## 8 /guTNnSWS3CaH71jasY8W1FMptjG.jpg movie 12, 28, 35, 53, 80
## 9 /phFpSgDbgp4j6Eg0fhmueC3uyVS.jpg movie 35
## 10 /txg7L67hkFQb7Sa0FzyuJwtxYaO.jpg movie 14, 27, 35
## 11 /oeQoePt9S4V3KHhZK1CWZE2yJrr.jpg movie 18, 35
## 12 /rRNsAIYiJdQHULseGsV9fQSOTDc.jpg movie 35, 10751
## 13 /efXWE0pzLchBKIXAKL3XmEQH1eo.jpg movie 18, 35, 80
## 14 /9KC8SBwUU3DzsXE6QQF6gk1Jy2d.jpg movie 35, 80, 28
## 15 /vQuIi5iOCN3V6yg7nbP5HUiVnpK.jpg movie 12, 16, 35, 14, 10751
## 16 /1uHTuwx5h9T3XzsXijMMKybDFvZ.jpg movie 35, 10751, 12, 80
## 17 /Awx3ld6kRqq0iMKPPCUTt1RidCn.jpg movie 16, 10751, 18, 14
## 18 /whxy3UQrbHswzXH6jfH7IGAIjLa.jpg movie 18, 10751, 14
## 19 /lktcffPqtBIL7OTuAN4pXgjXzOJ.jpg movie 35, 18, 14
## 20 /rcQZmnhcb6P4mkgJAHnCYp3c1gp.jpg movie 14, 18, 35, 10751
## 21 /fef2sQ0iuj1ZuhYZZTZIuVb2hZG.jpg movie 18, 14
## 22 /aTI2PMZbY09kKLn78plK3gCX3Vx.jpg movie 35, 27
## 23 /vkOQQ0zPTWzosHrcYcEhRJ17Uer.jpg movie 27, 9648, 53
## 24 /6xrA9tMvpb3cnktNH7voJ62S41N.jpg movie 35, 10749, 18
## 25 /8TNf3mbv4Wv9t6KMkxLUkCrB6SJ.jpg movie 35
## 26 /eSJtPyyz90IaXW5JFEJo9WSfPtk.jpg movie 27, 35, 14
## overview
## 1 It's the eve of Christmas in northern Finland and an archaeological dig has just unearthed the real Santa Claus. But this particular Santa isn't the one you want coming to town. When all the local children begin mysteriously disappearing, young Pietari and his father Rauno, a reindeer hunter by trade, capture the mythological being and attempt to sell Santa to the misguided leader of the multinational corporation sponsoring the dig. Santa's elves, however, will stop at nothing to free their fearless leader from captivity.
## 2 During a Christmas Eve in Tokyo, three homeless people, middle-aged alcoholic Gin, former drag queen Hana, and dependent runaway girl Miyuki, discover an abandoned newborn while looking through the garbage. With only a handful of clues to the baby's identity, the three misfits search the city to find its parents.
## 3 The comic mishaps and adventures of a young boy named Ralph, trying to convince his parents, teachers, and Santa that a Red Ryder B.B. gun really is the perfect Christmas gift for the 1940s.
## 4 Each Christmas, Santa and his vast army of highly trained elves produce gifts and distribute them around the world in one night. However, when one of 600 million children to receive a gift from Santa on Christmas Eve is missed, it is deemed ‘acceptable’ to all but one—Arthur. Arthur Claus is Santa’s misfit son who executes an unauthorised rookie mission to get the last present half way around the globe before dawn on Christmas morning.
## 5 NYPD cop John McClane's plan to reconcile with his estranged wife is thrown for a serious loop when, minutes after he arrives at her office, the entire building is overtaken by a group of terrorists. With little help from the LAPD, wisecracking McClane sets out to single-handedly rescue the hostages and bring the bad guys down.
## 6 Tired of scaring humans every October 31 with the same old bag of tricks, Jack Skellington, the spindly king of Halloween Town, kidnaps Santa Claus and plans to deliver shrunken heads and other ghoulish gifts to children on Christmas morning. But as Christmas approaches, Jack's rag-doll girlfriend, Sally, tries to foil his misguided plans.
## 7 When young Buddy falls into Santa's gift sack on Christmas Eve, he's transported back to the North Pole and raised as a toy-making elf by Santa's helpers. But as he grows into adulthood, he can't shake the nagging feeling that he doesn't belong. Buddy vows to visit Manhattan and find his real dad, a workaholic publisher.
## 8 Veteran buttoned-down LAPD detective Roger Murtaugh is partnered with unhinged cop Martin Riggs, who -- distraught after his wife's death -- has a death wish and takes unnecessary risks with criminals at every turn. The odd couple embark on their first homicide investigation as partners, involving a young woman known to Murtaugh with ties to a drug and prostitution ring.
## 9 A snobbish investor and a wily street con-artist find their positions reversed as part of a bet by two callous millionaires.
## 10 When Billy Peltzer is given a strange but adorable pet named Gizmo for Christmas, he inadvertently breaks the three important rules of caring for a Mogwai, and unleashes a horde of mischievous gremlins on a small town.
## 11 When their regal matriarch falls ill, the troubled Vuillard family come together for a hesitant Christmastime reunion. Among them is rebellious ne'er-do-well Henri and the uptight Elizabeth. Together under the same roof for the first time in many years, their intricate, long denied resentments and yearnings emerge again.
## 12 Eight-year-old Kevin McCallister makes the most of the situation after his family unwittingly leaves him behind when they go on Christmas vacation. But when a pair of bungling burglars set their sights on Kevin's house, the plucky kid stands ready to defend his territory. By planting booby traps galore, adorably mischievous Kevin stands his ground as his frantic mother attempts to race home before Christmas Day.
## 13 A miserable conman and his partner pose as Santa and his Little Helper to rob department stores on Christmas Eve. But they run into problems when the conman befriends a troubled kid, and the security boss discovers the plot.
## 14 A petty thief posing as an actor is brought to Los Angeles for an unlikely audition and finds himself in the middle of a murder investigation along with his high school dream girl and a detective who's been training him for his upcoming role...
## 15 When a doubting young boy takes an extraordinary train ride to the North Pole, he embarks on a journey of self-discovery that shows him that the wonder of life never fades for those who believe.
## 16 Instead of flying to Florida with his folks, Kevin ends up alone in New York, where he gets a hotel room with his dad's credit card—despite problems from a clerk and meddling bellboy. But when Kevin runs into his old nemeses, the Wet Bandits, he's determined to foil their plans to rob a toy store on Christmas eve.
## 17 Miser Ebenezer Scrooge is awakened on Christmas Eve by spirits who reveal to him his own miserable existence, what opportunities he wasted in his youth, his current cruelties, and the dire fate that awaits him if he does not change his ways. Scrooge is faced with his own story of growing bitterness and meanness, and must decide what his own future will hold: death or redemption.
## 18 A holiday favourite for generations... George Bailey has spent his entire life giving to the people of Bedford Falls. All that prevents rich skinflint Mr. Potter from taking over the entire town is George's modest building and loan company. But on Christmas Eve the business's $8,000 is lost and George's troubles begin.
## 19 In this modern take on Charles Dickens' "A Christmas Carol," Frank Cross (Bill Murray) is a wildly successful television executive whose cold ambition and curmudgeonly nature has driven away the love of his life, Claire Phillips (Karen Allen). But after firing a staff member, Eliot Loudermilk (Bobcat Goldthwait), on Christmas Eve, Frank is visited by a series of ghosts who give him a chance to re-evaluate his actions and right the wrongs of his past.
## 20 Scott Calvin is an ordinary man, who accidentally causes Santa Claus to fall from his roof on Christmas Eve and is knocked unconscious. When he and his young son finish Santa's trip and deliveries, they go to the North Pole, where Scott learns he must become the new Santa and convince those he loves that he is indeed, Father Christmas.
## 21 Scrooge is a miserly old businessman in 1840s London. One Christmas Eve he is visited by the ghost of Marley, his dead business partner. Marley foretells that Scrooge will be visited by three spirits, each of whom will attempt to show Scrooge the error of his ways. Will Scrooge reform his ways in time to celebrate Christmas?
## 22 A horror film that depicts St. Nicholas as a murderous bishop who kidnaps and murders children when there is a full moon on December 5.
## 23 A sorority house is terrorized by a stranger who makes frightening phone calls and then murders the sorority sisters during Christmas break.
## 24 Follows seemingly unrelated people as their lives begin to intertwine while they fall in – and out – of love. Affections languish and develop as Christmas draws near.
## 25 It's Christmas time and the Griswolds are preparing for a family seasonal celebration, but things never run smoothly for Clark, his wife Ellen and their two kids. Clark's continual bad luck is worsened by his obnoxious family guests, but he manages to keep going knowing that his Christmas bonus is due soon.
## 26 A horror comedy based on the ancient legend about a pagan creature who punishes children on Christmas.
## original_language original_title
## 1 fi Rare Exports
## 2 ja 東京ゴッドファーザーズ
## 3 en A Christmas Story
## 4 en Arthur Christmas
## 5 en Die Hard
## 6 en The Nightmare Before Christmas
## 7 en Elf
## 8 en Lethal Weapon
## 9 en Trading Places
## 10 en Gremlins
## 11 fr Un conte de Noël
## 12 en Home Alone
## 13 en Bad Santa
## 14 en Kiss Kiss Bang Bang
## 15 en The Polar Express
## 16 en Home Alone 2: Lost in New York
## 17 en A Christmas Carol
## 18 en It's a Wonderful Life
## 19 en Scrooged
## 20 en The Santa Clause
## 21 en A Christmas Carol
## 22 nl Sint
## 23 en Black Christmas
## 24 en Love Actually
## 25 en National Lampoon's Christmas Vacation
## 26 en Krampus
##
## $item_count
## [1] 26
##
## $iso_639_1
## [1] "en"
##
## $name
## [1] "Best Christmas Movies of All Time"
##
## $poster_path
## [1] "/8clzN9mg7ZgPLtrwjAimon7pRSH.jpg"
This example uses a more serious keyword.
search_keyword(key_get("TMDB_API"), query = "racism")
## $page
## [1] 1
##
## $results
## name id
## 1 racism 12425
## 2 anti-racism 257456
## 3 systemic racism 267085
## 4 gay racism 268247
## 5 systematic racism 268866
##
## $total_pages
## [1] 1
##
## $total_results
## [1] 5
one_page <- function(x) discover_movie(key_get("TMDB_API"), with_keywords = 12425, page = x)
pages <- 1:one_page(1)$total_pages
racism <- map_dfr(pages, function(x) one_page(x)$results)
glimpse(racism)
## Rows: 467
## Columns: 14
## $ original_title <chr> "Exodus: Gods and Kings", "Don't Be a Menace to Sou…
## $ title <chr> "Exodus: Gods and Kings", "Don't Be a Menace to Sou…
## $ video <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA…
## $ vote_average <dbl> 5.8, 6.8, 8.1, 8.1, 7.4, 7.6, 8.0, 8.1, 8.3, 7.8, 6…
## $ popularity <dbl> 44.312, 38.379, 37.681, 35.800, 33.774, 30.826, 26.…
## $ vote_count <int> 3496, 645, 616, 19481, 516, 12022, 6306, 7045, 7097…
## $ release_date <chr> "2014-12-03", "1996-01-12", "1993-02-05", "2012-12-…
## $ id <int> 147441, 10607, 9702, 68718, 502425, 419430, 381284,…
## $ adult <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA…
## $ backdrop_path <chr> "/hwowjWNnBc7PKZNDHQyLfvywzVY.jpg", "/3Q8RLOraAukMb…
## $ poster_path <chr> "/uaDj37JtvLan9tihxZ18e6qL33b.jpg", "/HZQBF7JDd2e9p…
## $ genre_ids <list> [<12, 18, 28>, 35, <28, 80, 18, 53>, <18, 37>, <18…
## $ overview <chr> "The defiant leader Moses rises up against the Egyp…
## $ original_language <chr> "en", "en", "en", "en", "en", "en", "en", "en", "en…